//
//  LZMyCompanyInfoTableView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/17.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyCompanyInfoTableView.h"
#import "LZMyCompanyInfoTableViewCell.h"
#import "Masonry.h"
#import "LZMerchantInfoModel.h"

@interface LZMyCompanyInfoTableView() <UITableViewDelegate, UITableViewDataSource>

@end

@implementation LZMyCompanyInfoTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self setup];
    }
    return self;
}

#pragma
#pragma mark private method

- (void)setup {
    self.backgroundColor = UIColorFromRGB(0xf9f7f7,1);
    self.separatorColor = [UIColor clearColor];
    self.dataSource = self;
    self.delegate = self;
}

#pragma
#pragma mark UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        LZMyCompanyInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier1"];
        if (!cell) {
            cell = [[LZMyCompanyInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                       reuseIdentifier:@"CellIdentifier1"
                                                               andType:LZ_MY_COMPANYINFO_CELLTYPE_TITLE];
        }
        
        cell.tag = indexPath.row;
        [cell setMerchantInfoModel:self.merchantInfoModel];
        return cell;
    }
    else if (indexPath.row == 1) {
        LZMyCompanyInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier2"];
        if (!cell) {
            cell = [[LZMyCompanyInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                       reuseIdentifier:@"CellIdentifier2"
                                                               andType:LZ_MY_COMPANYINFO_CELLTYPE_IMAGE];
        }
        
        cell.tag = indexPath.row;
        [cell setMerchantInfoModel:self.merchantInfoModel];
        cell.didTapImageBlock = ^(UITapGestureRecognizer * tapGR) {
            if (self.didTapImageBlock) {
                self.didTapImageBlock(tapGR);
            }
        };
        return cell;
    }
    else {
        LZMyCompanyInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier3"];
        if (!cell) {
            cell = [[LZMyCompanyInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                       reuseIdentifier:@"CellIdentifier3"
                                                               andType:LZ_MY_COMPANYINFO_CELLTYPE_ACCOUNT];
        }
        
        cell.tag = indexPath.row;
        [cell setMerchantInfoModel:self.merchantInfoModel];
        return cell;
    }
}

#pragma
#pragma mark UITableViewDelegate

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if(section == 0) {
    
        UIView * v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        v.backgroundColor = UIColorFromRGB(0xf8f8f8, 1);
        
        UILabel * textlabel = [[UILabel alloc] init];
        textlabel.font = [UIFont systemFontOfSize:12];
        textlabel.textColor = UIColorFromRGB(0xbababa, 1);
        textlabel.numberOfLines = 0;
        [v addSubview:textlabel];
        
        NSString * str = LZLocalizedString(@"tip_message", nil);
        
        NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle1 setLineSpacing:3];
        [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [str length])];
        [textlabel setAttributedText:attributedString1];
        
        [textlabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.leading.mas_equalTo(15);
            make.trailing.mas_equalTo(-15);
            make.bottom.mas_equalTo(-15);
        }];
        
        return v;
    }
    
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 0) {
        return 100;
    }
    
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        return 55.0f;
    }
    else if (indexPath.row == 1) {
        return 100.0f;
    }
    else
        return 89.0f;
}

@end
